Final exam - scheduled for 12/19/2024


Pipelining - start working on next instruction before previous instruction is done executing.

Idea: take picture (CPU diagram) and reposition components to come in stages/layers

As soon as first instruction moves to register file from instruction memory unit, second instruction can go to instruction memory unit.

MIPS pipelining stages

  1. Instruction fetch
  2. Instruction decode (including control unit, and register reading)
  3. Execution
  4. Memory access
  5. Write back

Note: in reality, there are 20-30 pipelining stages - the above is a simplified pipeline.

The more pipelining stages there are, the more efficient the CPU will be.

Pipeline hazards

Sometimes, there are situations where pipelining malfunctions or isn't possible - these are known as pipelining hazards.

Example: data and control hazards

# data hazard that can be fixed with data forwarding
# (compiler rearranging instructions)
addi $t0, $t1, 3
add $t2, $t0, $t4

# data hazard with no easy way out
lw $t0, 0($s1)
add $t2, $t0, $t4

# control hazard - will behave differently based on branch
beq $s1, $s2, L1
add $t0, $t0, $t0
sw $t0, 0($s7)
L1: addi $t0, $t0, -1

More terminology:

Data forwarding:

Branch prediction (aka speculative execution):